"""
Pytgon script for creating duplicate details in CSV format
"""
import MySQLdb
import csv
db = MySQLdb.connect(host="localhost", user="root", passwd="123",db="lsi_python")



str = "select distinct mainIssue FROM dupdetails_final"
cursor = db.cursor()
cursor.execute(str)

mainissues = cursor.fetchall()

for val in mainissues:
    print val[0]
    
cursor2 = db.cursor()    
for OneMainIssue in mainissues:
    str2 = "select * from dupdetails_final where mainIssue=\'%(val)s\'" %{'val':OneMainIssue[0]}   
    print str2 
    cursor.execute(str2)
    MainAndDup = cursor.fetchall()
    insertStr=MainAndDup[0][0]
    print "inint", insertStr
    row=0
    for i in MainAndDup:
        print i
        insertStr  = insertStr+","+ i[1]
        #row=row+1
    print "insert",insertStr 
    insertComm = "insert into dupdetails_final_denzil values(\'%(insert)s \')" %{'insert':insertStr}  
    print "insetComm",insertComm 
    cursor2.execute(insertComm)
    
db.commit()    
        
        
        
        